package com.zxq.factory.enums;

public enum EField {

    /**
     * 未知
     */
    Unknow(-1),
    /**
     * 一个标注，类似于改字段是一个包裹的包
     */
    Frame(0),
    /**
     * INT类型.默认左边高位，右边低位
     */
    Int(1),
    /**
     * 原封不动，用于包装，类似于ip 到 tcp
     */
    Bytes(2),
    /**
     * long类型
     */
    Long(3),
    /**
     * String编码
     */
    String(4),
    /**
     * bool类型
     */
    Boolean(5),
    /**
     * float类型
     */
    Float(6),
    /**
     * 双精度数值
     */
    Double(7),
    /**
     * 一般用来设备编号
     */
    Hex(8),
    /**
     *
     */
    CP56Time2a(10)
    ;
    int value;
    EField(int i) {
        this.value = i;
    }

    public int getValue() {
        return value;
    }

    public static EField getType(Integer value) {
        EField eField = EField.Unknow;
        switch (value) {
            case 0:
                eField = EField.Frame;
                break;
            case 1:
                eField = EField.Int;
                break;
            case 2:
                eField = EField.Bytes;
                break;
            case 3:
                eField = EField.Long;
                break;
            case 4:
                eField = EField.String;
                break;
            case 5:
                eField = EField.Boolean;
                break;
            case 6:
                eField = EField.Float;
                break;
            case 7:
                eField = EField.Double;
                break;
            case 8:
                eField = EField.Hex;
                break;
            case 10:
                eField = EField.CP56Time2a;
                break;
        }
        return eField;
    }

    public static Object getValue(Integer value) {
        Object objValue = null;
        switch (value) {
            case 1:
                objValue = 1L;
                break;
            case 2:
                objValue = new byte[]{0x01,0x02,0x03,0x04};
                break;
            case 3:
                objValue = 10L;
                break;
            case 4:
                objValue = "smile";
                break;
            case 5:
                objValue = true;
                break;
            case 6:
                objValue = 8.8f;
                break;
            case 7:
                objValue = 8.8d;
                break;
            case 8:
                objValue = "AABBCCDDEEFF";
                break;
            case 9:
                objValue = (byte)1;
                break;
            case 10:
                objValue = "34271 37 18 6 29 11 20（毫秒、分、时、星期日、月份日、月、年）";
                break;
        }

        return objValue;
    }



}
